<template>
  <div class="jingtiao">
    <div class="content_title" v-if="!inline">
      <span @click="showDialogTech" style="cursor:pointer">
        <span class="content_text">并条</span>
        <img class="content_img" src="../assets/img/resource/icon/jingtiao.png" alt="" srcset="" />
      </span>
    </div>
    <div class="jingtiao_body">
      <div class="jingtiaoCol">
        <div v-for="(item, index) in jingtiaoData.jingtiaoCol1Data" :key="index + 's'" class="jingtiao_item">
          <div v-if="index == 0">
            <div class="dongli" @click="clickHandleDl('jingtiao_' + index)">
              <img src="../assets/img/dongli.svg" alt="" srcset="" />
            </div>
          </div>
          <div @click="clickHandle('jingtiao', item)">
            <jingtiaol :data="item" :inline="inline"></jingtiaol>
          </div>
        </div>
        <template v-if="!inline">
          <div
            v-for="(item, index) in cushaData.cushaDataRow2Data"
            :key="index + 'd'"
            class="jingtiao_item"
            @click="clickHandle('cusha', item)"
          >
            <cusha :data="item" :inline="inline"></cusha>
          </div>
        </template>
      </div>
      <div class="jingtiaoCol">
        <div
          v-for="(item, index) in jingtiaoData.jingtiaoCol2Data"
          :key="index + 'f'"
          class="jingtiao_item"
          @click="clickHandle('jingtiao', item)"
        >
          <jingtiaor :data="item" :inline="inline"></jingtiaor>
        </div>
      </div>
    </div>
    <!-- 并条弹窗控件 -->
    <jingtiaoDialog ref="jingtiaoDialog" />
    <!-- 粗纱弹窗控件 -->
    <cushaDialog ref="cushaDialog2" />
    <!-- 动力柜弹窗控件 -->
    <dongliDialog ref="dongliDialog"></dongliDialog>
    <!-- 并条工艺详情 -->
    <jingtiao-dialog-tech v-if="techShow" ref="jingtiaoDialogTech"></jingtiao-dialog-tech>
  </div>
</template>

<script>
import dongliDialog from "../views/qcs/components/dialog/dialog_dongli/index";
import jingtiaoDialog from "../views/qcs/components/dialog/dialog_jingtiao/index";
import cushaDialog from "../views/qcs/components/dialog/dialog_cusha/index";
import jingtiaol from "../views/qcs/components/jingtiao_l";
import jingtiaor from "../views/qcs/components/jingtiao_r";
import cusha from "../views/qcs/components/cusha";
import COMMON from "../utils/common";
import dongLiMenu from "@/assets/data/dongli.json";
import dongliItem from "@/assets/data/dongliItem.json";
export default {
  name: "JingTiao",
  props: {
    msg: String,
    // 是否嵌套在弹窗内
    inline: {
      type: Boolean,
      default: false
    }
  },
  components: { dongliDialog, jingtiaol, jingtiaor, jingtiaoDialog, cushaDialog, cusha },
  data() {
    return {
      jingtiaoData: {
        // 1-12
        jingtiaoCol1Data: [],
        // 1-12
        jingtiaoCol2Data: []
      },
      cushaData: {
        // 15-16
        cushaDataRow2Data: []
      },
      dongLiMenu: {},
      dongLiItem: {},
      techShow: false
    };
  },
  // 组件相互调用 需在beforeCreate注册
  beforeCreate: function() {
    this.$options.components.jingtiaoDialogTech = require("../views/qcs/components/dialogBig/dialog_jingtiao_tech/index").default;
  },
  created() {
    this.dongLiMenu = dongLiMenu;
    this.dongLiItem = dongliItem;
  },
  methods: {
    closeHandle(type) {
      // 若并条组件在1.5级弹窗内，当关闭二级弹窗时，需要打开1.5级的轮询
      if (this.inline) {
        // 关闭二级轮询
        this.$EventBus.$emit("clearTypeInterval", type);
        this.$parent.$parent.getTableData();
      } else {
        this.$parent.closeParentHandle();
      }
    },
    clickHandle(flag, item) {
      switch (flag) {
        case "cusha":
          this.$parent.getInfoByDevSn("TXCSOML", item.devSn);
          this.$refs.cushaDialog2.showDialog(item);
          break;
        case "jingtiao":
          // 若并条组件在1.5级弹窗内，当打开二级弹窗时，需要关闭1.5级的轮询
          if (this.inline) {
            this.$EventBus.$emit("getInfoByDevSn", "BINGTIAO", item.devSn);
            this.$EventBus.$emit("inlineDialog", "close");
          } else {
            this.$parent.getInfoByDevSn("BINGTIAO", item.devSn);
          }
          this.$refs.jingtiaoDialog.showDialog(item);
          break;
      }
    },
    clickHandleDl(item) {
      var getInfoQuary = this.dongLiMenu[item];
      var dialogData = this.dongLiItem[item];
      // 若并条组件在1.5级弹窗内，当打开二级弹窗时，需要关闭1.5级的轮询
      if (this.inline) {
        this.$EventBus.$emit("getInfoByDevSn", "DONGLI", getInfoQuary);
        this.$EventBus.$emit("inlineDialog", "close");
      } else {
        this.$parent.getInfoByDevSn("DONGLI", getInfoQuary);
      }
      this.$refs.dongliDialog.showDialog(dialogData);
    },
    showDialogTech() {
      this.techShow = true;
      this.$nextTick(() => {
        setTimeout(() => {
          // 初始化请求
          // 1.5级轮询
          this.$parent.openInlineDialog("JINGTIAO", { start: 1, end: 112 });
          this.$refs.jingtiaoDialogTech.showDialog();
        });
      });
    },
    closeDialogTech() {
      this.techShow = false;
      this.$parent.closeParentHandle();
    }
  },
  computed: {
    bingTiaoGroupState() {
      return this.$store.state.bingTiaoGroupState;
    },
    txcsomlGroupState() {
      return this.$store.state.txcsomlGroupState;
    }
  },
  watch: {
    bingTiaoGroupState: {
      immediate: true,
      handler(val) {
        this.jingtiaoData.jingtiaoCol1Data = COMMON.devSnFilter(val.data, 1, 99);
        this.jingtiaoData.jingtiaoCol2Data = COMMON.devSnFilter(val.data, 99, 200);
      }
    },
    txcsomlGroupState: {
      immediate: true,
      handler(val) {
        this.cushaData.cushaDataRow2Data = COMMON.devSnFilter(val.data, 15, 16);
      }
    }
  }
};
</script>

<style scoped></style>
